<!-- <template>
  <a-button @click="showConfirm(), compile()">X</a-button>
</template>
<script lang="ts">
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import { createVNode, defineComponent, onMounted, onBeforeUnmount, ref } from 'vue';
import { Modal } from 'ant-design-vue';
import Bus from '@/mitt/index'
export default defineComponent({
  setup() {
    const showConfirm = () => {
      for (let i = 0; i < 1; i += 1) {
        setTimeout(() => {
          Modal.confirm({
            content: '删除',
            okText: "确定",
            icon: createVNode(ExclamationCircleOutlined),
            onOk() {
              return new Promise((resolve, reject) => {
                setTimeout(Math.random() > 0.5 ? resolve : reject, 1000);
              }).catch(() => console.log('确定删除'));
            },
            cancelText: '取消',
            onCancel() {
              Modal.destroyAll();
            },
          });
        }, i * 0);
      }
    };
    const compile = () => {
      Bus.emit('compile')
    }
    onMounted(() => {
      Bus.on('del', showConfirm)
    })
    onBeforeUnmount(() => {
      Bus.off('del', showConfirm)
    })
    return {
      showConfirm,
      compile
    };
  },
});
</script> -->
<template>
  <a-button @click="countDown">Open modal to close in 3s</a-button>
</template>
<script lang="ts">
import { Modal } from 'ant-design-vue';
import { defineComponent,onMounted,onBeforeUnmount } from 'vue';
import Bus from '@/mitt/index'
export default defineComponent({
  setup() {
    const countDown = () => {
      let secondsToGo = 3;
      const modal = Modal.success({
        title: '温馨提示',
        content: `这条会员的消息已经被彻底删除,无法复原,将于${secondsToGo}秒后面返回页面`,
      });
      const interval = setInterval(() => {
        secondsToGo -= 1;
        modal.update({
          content: `这条会员的消息已经被彻底删除,无法复原,将于${secondsToGo}秒后面返回页面`,
        });
      }, 1000);
      setTimeout(() => {
        clearInterval(interval);
        modal.destroy();
      }, secondsToGo * 1000);
    };
    onMounted(() => {
      Bus.on('del', countDown)
    })
    onBeforeUnmount(() => {
      Bus.off('del', countDown)
    })
    return {
      countDown,
    };
  },
});
</script>
<!-- 
  <template>
  <a-space wrap>
    <a-button @click="info">Info</a-button>
  </a-space>
</template>
<script lang="ts">
import { Modal } from 'ant-design-vue';
import { defineComponent, h } from 'vue';
export default defineComponent({
  setup() {
    const info = () => {
      Modal.info({
        title: 'This is a notification message',
        onOk() {
          console.log('ok');
        },
      });
    };
    return {
      info,
    };
  },
});
</script>
 -->

